---
--- Created by gu.
--- DateTime: 18/5/16 下午4:23
---
local val = redis.call('incr', KEYS[1])
local ttl = redis.call('ttl', KEYS[1])

redis.log(redis.LOG_NOTICE, "incr "..KEYS[1].." "..val);
if val == 1 then
    redis.call('expire', KEYS[1], tonumber(ARGV[1]))
else
    if ttl == -1 then
        redis.call('expire', KEYS[1], tonumber(ARGV[1]))
    end
end

if val > tonumber(ARGV[2]) then
    return 0
end

return 1